package public

import (
	"time"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/crypto/gmd5"
	"github.com/gogf/gf/os/gtime"
	"github.com/gogf/gf/util/gconv"
)

// 云短信对接
func (c *GatewayClient) SendSms(phone, code, template string) (string, error) {
	timestamp := gtime.Timestamp()
	Sign := g.Cfg().GetString("cyt_gateway.ydx.sig_content", "Dianba")
	AppId := g.Cfg().GetInt64("cyt_gateway.ydx.app_id", 3)
	AppKey := g.Cfg().GetString("cyt_gateway.ydx.app_key", "djjhvd24UoyRRjfXgNfhiovfvDRvpTgv")
	AppSecret := g.Cfg().GetString("cyt_gateway.ydx.app_secret", "Ku5NMV2DEhsPzfx9JLfig2VNfLNzFS8Z")
	headers := g.MapStrStr{
		"SMS-APP-ID": gconv.String(AppId),
		"SMS-SIGNATURE": gmd5.MustEncrypt(gmd5.MustEncrypt(gmd5.MustEncrypt(gconv.String(timestamp + AppId)) + AppSecret) + AppKey),
		"SMS-TIME": gconv.String(timestamp),
	}
	params := g.Map{
		"phone": phone,
		"sig_content": Sign,
		"template_uid": template,
		"params": g.ArrayStr{code, "10"},
	}
	response := c.Client.ContentJson().SetHeaderMap(headers).SetRetry(5, 5 * time.Second).PostContent("/ydx/api/app/send", params)
	return response, nil
}